package com.helloandroid.base

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

abstract class BaseFragment : Fragment() {

    lateinit var mContext:Context
    lateinit var mView:View

    override fun onAttach(context: Context) {
        super.onAttach(context)
        mContext = context
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mView = inflater.inflate(getLayoutResId(), container, false)
        return mView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView(view)
        initData()
    }

    abstract fun getLayoutResId(): Int
    abstract fun initView(view: View)
    abstract fun initData()

    fun  <T:View> findViewById(viewId:Int): T = mView.findViewById<T>(viewId)
    fun findBtn(viewId:Int):View = mView.findViewById(viewId)
}